package com.mdd.maduoduo.data;

import com.orhanobut.logger.Logger;
import com.mdd.maduoduo.data.exception.ApiException;
import com.mdd.maduoduo.entity.ResponseBody;


import io.reactivex.functions.Function;

public class NetworkResultHandler {

    public static <T> Function<ResponseBody<T>, T> handlerResult() {
        return responseBody -> {
            if (!responseBody.isSuccess()) {
                throw new ApiException(responseBody.getMsg());
            }
            Logger.d(responseBody.getResult() != null ? responseBody.getResult().toString() : "null");
            return responseBody.getResult();
        };
    }

    public static <T> Function<T, T> handlerDataResult() {
        return t -> t;
    }
}
